﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Forgot password</title>
    <script src="md5.js" type="text/javascript"></script>
</head>
<body>
    <h3 class="fg-color-dark">
        Enter the email address associated with your account.
    </h3>
    <div class="input-control text ">
        <input type="email" id="idUserID"  class="fg-color-black" placeholder='Enter your email address' style="color:black;" />
    </div>
    <h3 class="fg-color-red icon-eye" style=" border:1px dotted red; display:none;" id='idErrorForgot'></h3>
    <button id="idRetrievePassword" class=" bg-color-darken  fg-color-white"> Submit <i class="icon-unlocked"></i></button>
</body>
<script type="text/javascript">
    $('#idRetrievePassword').click(function ()
    {
        var email = $('#idUserID').val();
        $(this).hide();
        if (!isValidMail(email))
        {
            ShowErrorMsg("Invalid Email, Please retry it!");
            $(this).show();
        }
        else
        {
            //var dt = new Date();
            //var str = (dt.getYear() + dt.getMonth() + dt.getDate() + dt.getHours() + dt.getMinutes() + dt.getSeconds() + dt.getMilliseconds());
            var code = hex_md5(email);
            $.ajax({
                type: "POST",
                url: "Login.ashx",
                data: "mode=ForgotPassword&code=" + code + "&id=" + email,
                async: true,
                success: function (data)
                {
                    var r = eval('(' + data + ')');
                    if ('False' == r["ret"])
                    {
                        ShowErrorMsg(r["msg"]);
                        $('#idRetrievePassword').show();
                    }
                    else
                    {
                        SendEmail(email, code);
                    }
                }
            });
        }
    });


    function SendEmail(email, code)
    {
        ShowErrorMsg("Processing...");
        $.ajax({
            type: "POST",
            url: "Login.ashx",
            data: "mode=SendEmail&id=" + email + "&code="+code,
            async: false,
            success: function (data)
            {
                if ('1' == data)
                {
                    ShowErrorMsg("An temperatory URL has been sent to your Email address, please check");            
                }
                $('#idRetrievePassword').show();
            }
        });
        
    }
    function ShowErrorMsg(data)
    {
        var err = $('#idErrorForgot');
        err.html(data);
        err.show();
    }
</script>
</html>
